#include "GLButtonEvent.h"

namespace mp_gl
{
	GLButtonEvent::GLButtonEvent()
		:Event()
	{
		//Set default trigger
		m_pressTrigger = (BTN_PRESS);
		m_prevPressType = BTN_RELEASE;
		m_currentPressType = BTN_RELEASE;
		m_repeatTriggerTime = 0.0;
		m_lastTimeStamp = 0.0;
		m_timeSpan = 0.0;
	}
	
	bool GLButtonEvent::IsTriggered()
	{
		bool tmp = false;
		if ( tmp = (m_triggerCount > 0) )
			m_triggerCount--;
		return tmp;
	}

	
	void GLButtonEvent::Update(GLFWwindow* window)
	{
		switch (m_pressTrigger)
		{
		case BTN_UP:
			if (m_currentPressType == BTN_UP)
				m_triggerCount++;
			break;
		case BTN_DOWN:
			if (m_currentPressType == BTN_DOWN)
				m_triggerCount++;
			break;
		case BTN_PRESS:
			if (m_currentPressType	== BTN_DOWN &&
				m_prevPressType		== BTN_UP)
				m_triggerCount++;
			break;
		case BTN_RELEASE:
			if (m_currentPressType	== BTN_UP &&
				m_prevPressType		== BTN_DOWN)
				m_triggerCount++;
			break;
		case BTN_HELD:
			if (m_currentPressType == BTN_DOWN)
			{

			}
			break;
		default:
			break;
		}
		m_prevPressType = m_currentPressType;
	}
}